package main

import (
	"fmt"
	"log"
	"os"

	"github.com/ftomza/gogost/gost34112012256"
	"github.com/ftomza/gogost/gost34112012512"
	"github.com/ftomza/gogost/gost341194"
	"github.com/pborman/getopt"
)

func hashing(pathstr string, cipher string) {
	file, fileError := os.Open(pathstr)
	if fileError != nil {
		log.Fatal(fileError)
	}
	defer file.Close()

	stat, statError := file.Stat()
	if statError != nil {
		log.Fatal(statError)
	}

	buf := make([]byte, stat.Size())

	n, fileReadError := file.Read(buf)
	if fileReadError != nil {
		log.Fatal(fileReadError)
	}
	var hashstr []byte
	if cipher == "gost2012" {
		hasher := gost34112012256.New()

		_, _ = hasher.Write(buf[:n])

		hashstr = hasher.Sum(nil)

	}

	if cipher == "gost2012512" {
		hasher := gost34112012512.New()

		_, _ = hasher.Write(buf[:n])

		hashstr = hasher.Sum(nil)

	}

	if cipher == "gost94" {
		hasher := gost341194.New(gost341194.SboxDefault)

		_, _ = hasher.Write(buf[:n])

		hashstr = hasher.Sum(nil)

	}
	fmt.Printf("%x\n", hashstr)

	parseError := getopt.Getopt(nil)
	if parseError != nil {
		// обработка ошибки принятия аргументов
		fmt.Fprintln(os.Stderr, parseError)
	}
}
